export function isParent(obj, parentObj) {
  // 判断obj元素是否在parentObj内部
  while (obj !== undefined && obj !== null && obj.tagName.toUpperCase() !== 'BODY') {
    if (obj === parentObj) {
      return true;
    }
    obj = obj.parentNode;
  }
  return false;
}

export const getParams = (url) => {
  const params = url.split('?')[1];
  const paramsArr = params.split('&');
  let obj = {};
  paramsArr.map(item => {
    const items = item.split('=');
    obj[items[0]] = items[1];
  })
  return obj;
}

export const getNotEmptyObj = (obj) => {
  let newObj = {};
  Object.keys(obj).map(item => {
    if(obj[item] !== null && obj[item] !== undefined && obj[item] !== ''){
      newObj[item] = obj[item];
    }
  })
  return newObj;
}

export const getPickerData = (data, label='parameterName', value='id', children='children') => {
  let arr = [];
  data && data.map(item => {
    if(item[children]){
      let sons = getPickerData(item[children], label, value, children);
      arr.push({...item, label: item[label], value: item[value], children: sons});
    }else{
      arr.push({...item, label: item[label], value: item[value]});
    }
  })
  return arr;
} 

export const getLabelValueData = (data, label='parameterName', value='id') => {
  return data.map(item => ({...item, label: item[label], value: item[value]}));
}
